package com.Service;

import com.Dao.PoDao;
import com.POJO.Po;
import com.Service.Imp.PoServiceImp;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

@Service
public class PoService extends ServiceImpl<PoDao, Po> implements PoServiceImp {
    @Autowired
    private PoDao poDao;
    public  int addPo(String tel,String username,String category1,String category2,String goodsName,String goodsContent,String province,String city,String area,String addressIp,String longitude,String latitude,String money       ){
        Po po=new Po();
        String uuid= UUID.randomUUID().toString();
        po.setOrderUuid(uuid);
        po.setTel(tel);
        po.setUsername(username);
        po.setCategory1(category1);
        po.setCategory2(category2);
        po.setGoodsName(goodsName);
        po.setGoodsContent(goodsContent);
        po.setProvince(province);
        po.setCity(city);
        po.setArea(area);
        po.setAddressIp(addressIp);
        po.setLongitude(new BigDecimal(longitude));
        po.setLatitude(new BigDecimal(latitude));
        po.setMoney(new BigDecimal(money));
        po.setState("1");
        return poDao.insert(po);
    }

    public List<Po> findPo(String tel,String state){
        QueryWrapper<Po> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("tel",tel);
        if(!Objects.equals(state, "0"))
        queryWrapper.eq("state",state);
        return poDao.selectList(queryWrapper);
    }

    public List<Po> findUserPo(String state){
        QueryWrapper<Po> queryWrapper=new QueryWrapper<>();
        if(!Objects.equals(state, "0"))
            queryWrapper.eq("state",state);

        return poDao.selectList(queryWrapper);
    }

    public int updataState(String uuid ,String state){
        Po po=new Po();
        UpdateWrapper<Po> updateWrapper=new UpdateWrapper<>();
        updateWrapper.set("state",state);
        updateWrapper.eq("order_uuid",uuid);
        return poDao.update(po,updateWrapper);
    }
}
